<style lang="less">
@import url("../static/css/base/reset.less");
@import url("../static/css/base/animate.min.css");
.bg {
  background-size: 100%;
  background-repeat: no-repeat;
}
.btn {
  margin: auto;
  &:extend(.bg);
  width: 268px;
  height: 48px;
  font-size: 19px;
  color: #fff;
  line-height: 44px;
  text-align: center;
}
@red: #441f00;
.page3 {
  background-image: url("../static/image/bg_02.jpg");
  width: 100%;
  height: 100%;
  background-size: 100% 100%;
  background-repeat: no-repeat;
}

.footer {
  width: 100%;
  height: 136px;
  background-image: url("../static/image/bg_footer.png?__sprite");
  .bg();
  position: fixed;
  bottom: 0;
  z-index: 10;
  .btnbox {
    position: relative;
    height: 100%;
    width: 100%;
  }
  .btn_city {
    position: absolute;
    left: 0;
    height: 66px;
    width: 96px;
    bottom: 0;
  }
  .btn_call {
    position: absolute;
    right: 0;
    height: 66px;
    width: 96px;
    bottom: 0;
  }
}
.callBox {
  // height: 100%;
  // width: 100%;
  .heart {
    background-image: url("../static/image/icon_heart.png?__inline");
    width: 90px;
    height: 80px;
    .bg();
    position: fixed;
    bottom: 92px;
    margin: auto;
    left: 0;
    right: 0;
    z-index: 11;
  }
  .plus1 {
    font-size: 80px;
    color: #fff;
    z-index: 11;
    position: fixed;
    margin: auto;
    left: 0;
    right: 0;
    top: 29.56%;
    line-height: 1;
    text-align: center;
    em {
      font-size: 60px;
    }
  }
  .showTimer {
    position: absolute;
    top: 46.18%;
    font-size: 15px;
    color: #fff;
    line-height: 1;
    z-index: 10;
    text-align: center;
    margin: auto;
    left: 0;
    right: 0;
  }
}
.maskH {
  width: 100%;
  height: 100%;
  background-color: rgba(22, 21, 26, 0.74);
  position: fixed;
  z-index: 9;
  top: 0;
}
.plus1_a {
  animation: plus1 0.5s 1;
  z-index: 6;
}
@keyframes plus1 {
  0% {
    opacity: 0.5;
    top: 70%;
    transform: scale(0.2);
  }
  50% {
    transform: scale(0.5);
  }
  99% {
    top: 29.56%;
    opacity: 1;
    transform: scale(1);
  }
  100% {
    opacity: 0;
  }
}
// 结束
.shareBtn {
  width: 144px;
  height: 44px;
  background-image: url("../static/image/btn_share.png?__sprite");
  .bg();
}
.phoneBtn {
  &:extend(.shareBtn);
  background-image: url("../static/image/btn_phone.png?__sprite");
}
.shareBox {
  width: 308px;
  position: fixed;
  top: 76.41%;
  z-index: 10;
  margin: auto;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
}
</style>
<template>
<div class="page3">
  <vueHeader></vueHeader>
  <vueInfo :cityCode="cityCode"></vueInfo>
  <div class="footer">
    <div class="btnbox"  v-show="calling!=1">   
    <router-link class="btn_city" to="/cities"> </router-link>
    <div class="btn_call" @click="initPop('amount')"> </div>
    </div>
  </div>
  <div class="callBox">
    <div :class="pulseHeart" v-show="!saving" @click="addOne"></div>
    <div :class="plusAnimate" ref="plus1" v-show="plusAnimate.length==2"><em>+</em>1</div>
    <div class="showTimer" v-show="calling==1">倒计时{{showTime}}s</div>
  </div>
  <div class="shareBox" v-show="saving">
    <div class="shareBtn"></div>
    <div class="phoneBtn" @click="initPop('phone2')"></div>
  </div>
  <vuePop :city="{city,cityCode}" :info="popInfo" :status="popStatus1" v-if="popInfo"></vuePop>
  <div class="maskH" v-show="!!mask||calling==1"></div>
  </div>
</template>

<script>
import ajaxData from "../static/modules/ajaxData";
import vueHeader from "./header";
import vueInfo from "./cityInfo";
import vuePop from "./pop";
import util from "../static/modules/util";
import pop_routers from "../static/modules/pop_routers";
export default {
  components: {
    vueHeader,
    vueInfo,
    vuePop
  },
  props: ["cityCode", "popStatus"],
  data() {
    return {
      city: "",
      calling: 0,
      mask: false,
      saving: false,
      pulseHeart: ["heart", "animated", "pulse", "infinite"],
      plusAnimate: ["plus1"],
      calls: 0,
      callTimer: null,
      showTime: 3,
      popInfo: null,
      popStatus1: this.popStatus || 0
    };
  },
  created() {
    this.init();
    this.initPop();
  },
  methods: {
    ...pop_routers,
    init() {
      this.city = util.storage.getItem("my_city");
      console.log(bus);
      ajaxData.status2((data,code)=>{
        if(code==406){
          this.calling=2;
        }
        util.storage.setItem('usrPhone',data.phone);
      });
      bus.$on("closePop",()=>{
        this.initPop("close");
      })
    },
    initPop(str = this.popStatus1, ...data) {
      this.popStatus1 = str;
      if (!str) {
        return;
      } else {
        this.mask = 1;
        this["pop_" + str](...data);
      }
    },
    addOne() {
      if(this.calling==2){
        this.initPop('has');
        return;
      }
      if (this.calling!=1 && !this.saving) {
        this.calling = 1;
        this.showTimer();
        this.callTimer = setInterval(() => {
          clearInterval(this.callTimer);
          this.initPop("now");
          this.calling = 0;
        }, this.showTime*1000);
      }
      this.calls++;
      if (this.plusAnimate.length == 2) {
        return;
      }
      this.plusAnimate = ["plus1_a", "plus1"];
      setTimeout(() => {
        this.plusAnimate = ["plus1"];
      }, 500);
    },
    showTimer() {
      let timer = setInterval(() => {
        this.showTime--;
        if (!this.showTime) {
          clearInterval(timer);
        }
      }, 1000);
    }
  },
  watch: {
    $route(to, from) {
      // if (to.params.popStatus == "close") {
      //   this.initPop('close');
      // this.$router.push(`/my_city/${this.cityCode}`);
      // }
    }
  }
};
</script>
